<?php
namespace app\common\validate;
use think\Validate;
use think\Request;
class Jifen extends Validate{
    protected $rule =   [
    	'taskid' => 'number|checkTaskid',
    ];

    protected $message  =   [
        'taskid.number' => 'taskid必须是数字',
    ];
    protected $scene = [
    	'check_task' => ['taskid'=>'checkTaskid']
    ];
    //0:兑换积分，1:签到积分，2:晒单积分，3:分享积分，4:注册积分，5:登录积分
    public function checkTaskid($value, $rule=[], $data){
        switch ($value) {
            case 1:
                $count = model("Jifen")->where('userid', $data['userid'])->where('taskid', 1)->whereTime('addtime', 'today')->count();
                return $count ? '今日已签到，一天只能签到一次。' : true;
                break;
            case 2:
                $count = model("Jifen")->where('userid', $data['userid'])->where('taskid', 2)->whereTime('addtime', 'today')->count();
                return $count >= 3 ? '今日晒单已经3次，不能继续获取积分。' : true;
                break;
            case 3:
                $count = model("Jifen")->where('userid', $data['userid'])->where('taskid', 3)->whereTime('addtime', 'today')->count();
                return $count >= 5 ? '今日分享已经5次，不能继续获取积分。' : true;
                break;
            case 4:
                $count = model("Jifen")->where('userid', $data['userid'])->where('taskid', 4)->count();
                return $count ? '只能获取一次注册积分。' : true;
                break;
            case 5:
                $count = model("Jifen")->where('userid', $data['userid'])->where('taskid', 5)->whereTime('addtime', 'today')->count();
                return $count ? '每日登陆只可获取一次登录积分。' : true;
                break;
        }
    	return true;
    }
}